<!--
*@Author: zt
*@Description: 任务报表填报编辑
*@Date: 2024-09-02
-->
<template>
  <u-dialog
    v-bind="$attrs"
    :confirmLoading="loading"
    @close="dialogClose"
    @submit="submit">
    <a-layout class="f-h-100 u-dialog-all-bg">
      <a-layout-content
        class="s-bg-white"
        style="overflow: auto">
        <a-space
          direction="vertical"
          class="f-w-100">
          <u-busi-card
            title="基本信息"
            :bordered="false">
            <u-form
              :elements="formEls"
              :model="form"
              :gutter="0"
              :loading="loading"
              :disabled="true"
              ref="formRef"></u-form>
          </u-busi-card>

          <u-busi-card
            title="上传附件"
            :bordered="false">
            <u-field-upload
              v-model:value="fileData"
              :fileParams="{
                bucket: 'EXE_BIZ_TYPE_USER',
                biztype: '2',
              }"></u-field-upload>
          </u-busi-card>
        </a-space>
      </a-layout-content>
    </a-layout>
  </u-dialog>
</template>

<script lang="ts" setup>
import { ref, reactive, computed, onMounted, h, useAttrs, watch } from "vue";
import { useRoute, useRouter } from "vue-router";
import { _IFormEl, _IExtra } from "@/src/components/common/form/interface";
import { FormInstance, FormItemProps } from "ant-design-vue";
import { HomeOutlined, FileTextOutlined, UploadOutlined } from "@ant-design/icons-vue";
import { TreeProps } from "ant-design-vue/es/vc-tree";
import { ColumnProps } from "ant-design-vue/es/table";
import { _IColumnProps } from "@/components/common/tableEdit/interface.ts";
import { fileCols } from "@/common/model/fileCols";
import { regions, depts, users } from "@/common/model/base";
import { alertC, messageC } from "@/util/common";
import dayjs from "dayjs";
import * as dynamicReportApi from "@/service/emergency/dynamicReport";

const attrs = useAttrs();
const route = useRoute();

const emits = defineEmits(["submit", "close"]);

const loading = ref<boolean>(false);
let fileData = ref([]);
const formRef = ref<FormInstance>();
const form = reactive({});
const formItemProps: FormItemProps & _IExtra = {
  labelWidth: "150px",
  colon: false,
};
const formEls: Array<_IFormEl> = [
  {
    label: "任务名称",
    key: "filename",
    col: { span: 24 },
    element: "input",
    formItemProps: {
      ...formItemProps,
      rules: {
        pattern: /^[\u4e00-\u9fa5]{3,}$/,
        message: "名称需要在3个中文字符以上",
      },
    },
    componentProps: {
      disabled: true,
    },
  },
  {
    label: "开始日期",
    key: "startdate",
    col: { span: 12 },
    element: "datepicker",
    formItemProps: { ...formItemProps },
    componentProps: {
      disabled: true,
    },
  },
  {
    label: "结束日期",
    key: "enddate",
    col: { span: 12 },
    element: "datepicker",
    formItemProps: { ...formItemProps },
    componentProps: {
      disabled: true,
    },
  },
  {
    label: "任务结束前提醒",
    key: "isend",
    col: { span: 12 },
    element: "input",
    formItemProps: { ...formItemProps },
    componentProps: {
      disabled: true,
    },
  },
  // {
  //   label: '任务超时后提醒',
  //   key: 'isover',
  //   col: { span: 12 },
  //   element: 'input',
  //   formItemProps: { ...formItemProps },
  //   componentProps: {
  //     disabled: true,
  //   },
  // },
  {
    label: "任务说明",
    key: "remark",
    col: { span: 24 },
    element: "textarea",
    formItemProps: { ...formItemProps },
    componentProps: {
      disabled: true,
    },
  },
  {
    label: "报表模版",
    key: "saveVO",
    col: { span: 24 },
    element: "file",
    formItemProps: { ...formItemProps },
    componentProps: {
      disabled: true,
      fileParams: { biztype: "2", bucket: "EXE_BIZ_TYPE_USER", maxCount: 1 },
    },
  },
];

// 弹窗关闭
const dialogClose = () => {
  formRef.value.form.resetFields();
};

//获取数据
const getSearch = async (keyid: any) => {
  const res = await dynamicReportApi.searchTask({ fkFormsid: keyid });
  if (res.code == 0) {
    for (let k in res.data.exeTForms) {
      form[k] = res.data.exeTForms[k];
    }
    form["saveVO"] = res.data.formAttachList;
    // tabData.value = res.data.appendisUserMapList;
  }
};

//提交
const submit = async () => {
  if (!fileData.value.length) {
    messageC("请上传附件", "warning");
    return;
  }

  loading.value = true;
  try {
    const res = await dynamicReportApi.insertTask({
      fkformid: attrs.keyid,
      appendixSaveVOList: fileData.value,
    });
    if (res.code == 0) {
      messageC("任务报表填报编辑成功", "success");
      emits("success");
    } else {
      messageC(res.msg, "error");
    }
  } catch (error) {}
  loading.value = false;
};

watch(
  () => attrs.open,
  async (nval, oval) => {
    if (nval == true) {
      fileData.value = [];
      await getSearch(attrs.keyid);
    }
  }
);
</script>

<style lang="scss">
.u-dialog-all-bg {
  position: absolute !important;
  left: 0;
  padding: 20px;
  width: 100%;
  height: calc(100vh - 130px);
}
</style>
